# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon

from coin.proto.coin_feed_subscriber_pb2 import FeedSubscriberConfig
from coin.strategy.mm.subscription import (SubscriptionRequest)
from coin.strategy.mm.feed_subsystems import get_feed_subsystem_cls


def get_flow_book_builder_cls(sub_key, *, fs_config=None, current_datetime=None):
  assert type(sub_key) == SubscriptionRequest, type(sub_key)
  feed_subsystem_cls = get_feed_subsystem_cls(sub_key,
                                              fs_config=fs_config,
                                              current_datetime=current_datetime)
  return feed_subsystem_cls.FlowBookBuilder


def get_flow_book_builder(sub_key,
                          flow_sub,
                          worker_id='1',
                          feed_checker_config=None,
                          fs_config=None,
                          current_datetime=None,
                          book_builder_opts=None):
  book_builder_cls = get_flow_book_builder_cls(sub_key=sub_key,
                                               fs_config=fs_config,
                                               current_datetime=current_datetime)
  kwargs = {}
  if book_builder_opts:
    kwargs['book_builder_opts'] = book_builder_opts
  return book_builder_cls(flow_sub, worker_id, feed_checker_config=feed_checker_config, **kwargs)
